
use tables/estimates_unwtd_bs_ci, clear 

/*
weekly bounds
- population
- icli 
- non-icli, h-m
- non-icli, h-i
- clear, h-m
- clear, h-i 
*/

** set up for reshape 
rename lb_pop lb_pop0
rename ub_pop ub_pop0 
rename p025_pop lb_pop1
rename p975_pop ub_pop1

foreach t in non clear icli {
	foreach suff in i m {
		rename lb_`t'_`suff' lb_`t'_`suff'0
		rename ub_`t'_`suff' ub_`t'_`suff'0
		rename p025_`t'_`suff' lb_`t'_`suff'1
		rename p975_`t'_`suff' ub_`t'_`suff'1
	}
}

keep week lb_* ub_*
reshape long lb_pop ub_pop lb_non_i ub_non_i lb_non_m ub_non_m ///
	lb_icli_m lb_icli_i ub_icli_m ub_icli_i ///
	lb_clear_i lb_clear_m ub_clear_i ub_clear_m, i(week) j(ci)

foreach v of varlist lb_* {
	gen s = string(`v', "%5.4f") + ", "
	drop `v'
	rename s `v'
	replace `v' = "[" + `v' if ~ci
	replace `v' = "(" + `v' if  ci
}

foreach v of varlist ub_* {
	gen s = string(`v', "%4.3f")
	drop `v'
	rename s `v'
	replace `v' = `v' + "] &" if ~ci
	replace `v' = `v' + ") &" if  ci
}
gen weeks = string(week, "%td") 
replace weeks  = subinstr(weeks, "2020", "", .) + " & "
replace weeks =  " & " if ci
list weeks lb_pop ub_pop in 1/2
replace ub_clear_i = subinstr(ub_clear_i, "&", "\\" , .)

# delimit ;
outsheet weeks lb_pop ub_pop 
	lb_non_m ub_non_m lb_non_i ub_non_i
	lb_clear_m ub_clear_m lb_clear_i ub_clear_i if month(week)<=7
	using tables/bounds_by_group_Mar_Jul.tex, 
	replace noquote noname delimit(" ")
;
outsheet weeks lb_pop ub_pop 
	lb_non_m ub_non_m lb_non_i ub_non_i
	lb_clear_m ub_clear_m lb_clear_i ub_clear_i if month(week)>=8
	using tables/bounds_by_group_Aug_Dec.tex, 
	replace noquote noname delimit(" ")
;
# delimit cr
	

